aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/[username]/+layout.server.js
blob: 27502386e84eec3efe8c9483f69991edb9e09978 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { get } from '$lib/utils';
import { error } from '@sveltejs/kit';

export let load = async ({ depends, params: { username } }) => {
	depends('app:user');

	try {
		let subject = await get(`/users/${username}`);
		return { subject };
	} catch (e) {
		console.log(e);
		throw error(500, 'Unable to retrieve user account data');
	}
};
t/blame/src/routes/(app)/invoice/[id]/+page.svelte?h=liquid&id=545c5a016eba8128d4ade02aa506b8821a00a38c'>^
1072c7a2 ^
28edb9a1 ^
1072c7a2 ^
adf27ffe ^

1072c7a2 ^




ccc13974 ^

376ff340 ^
4b15454e ^
28edb9a1 ^
cfdc6ed4 ^
1072c7a2 ^



28edb9a1 ^
1072c7a2 ^
28edb9a1 ^
1072c7a2 ^
adf27ffe ^

1072c7a2 ^




08892d21 ^
1072c7a2 ^

544637e3 ^
544637e3 ^
363f1b23 ^
f0d88333 ^








28edb9a1 ^


376ff340 ^






4aa1ad89 ^
eb9a9c04 ^
2af4a989 ^
363f1b23 ^

577f7483 ^
f5c87f1b ^





4b15454e ^
4abcb74a ^
4b15454e ^
f5c87f1b ^
4abcb74a ^


f5c87f1b ^
4b15454e ^
4abcb74a ^
f5c87f1b ^
2cbe7c28 ^
f5c87f1b ^

ccc13974 ^
f5c87f1b ^

4abcb74a ^

2cbe7c28 ^
f5c87f1b ^





8851572f ^
f5c87f1b ^










4abcb74a ^
f5c87f1b ^














4abcb74a ^
4abcb74a ^

e195d2fe ^
f5c87f1b ^















577f7483 ^
a038ce97 ^

28edb9a1 ^



c230185c ^


a038ce97 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
        
                                           
                                                                                     
                                                          
                                                   

                                                               
                                               
                                              
                                            
 
                        
 
                         
                                                 
             
                        
                       
                        
                     

                         




                                            

                             
                     
 
               
                           



                                         
                                
                               
                                
                             

                                 




                                                    
                                                  

          
                                                                        
                                                        
 








                                                           


                                                       






                                      
         
 
                                                                             

                                               
 





                                                                              
                                                                                                                
                                                                  
                                                                                        
                                                                                             


                                              
                      
              
 
                                                           
                                     

                                                                                                                 
 

                                                                   

                     
                                                       





                                                                                                     
                      










                                                                                              
 














                                                                                                                      
                                 

                              
              















                                                                                                                 
      

       



                           


                                                                   
        
<script>
	import { send } from '$lib/socket';
	import { back, copy, f, get, sat, reverseFormat, s, sats } from '$lib/utils';
	import { tick, onMount, onDestroy } from 'svelte';
	import { browser } from '$app/environment';
	import { invoices, last } from '$lib/store';
	import { Avatar, Icon, Heart, Image, Qr } from '$comp';
	import { goto } from '$app/navigation';
	import { t } from '$lib/translations';
	import screenfull from 'screenfull';

	export let data;

	$: refresh(data);
	let { invoice, id, user, sm, lg } = data;
	let {
		address,
		amount,
		network,
		rate,
		received,
		prompt,
		text,
		tip,
		user: { username, currency }
	} = invoice;

	let showQr = !amount;

	let src = sm;

	let qr;
	let tipPercent = 0;

	let refresh = (data) => {
		({ invoice, id } = data);
		({
			address,
			amount,
			network,
			rate,
			received,
			prompt,
			text,
			tip,
			user: { username, currency }
		} = invoice);

		tipPercent = (tip / amount) * 100;
	};

	$: amountFiat = parseFloat(((amount * rate) / sats).toFixed(2));
	$: tipAmount = ((tip * rate) / sats).toFixed(2);

	let subbed;
	onMount(() => {
		browser &&
			last.subscribe((v) => {
				if (!v || subbed) return;
				subbed = true;
				send('subscribe', invoice);
			});
	});

	$: link = address ? text : `lightning:${text}`;

	let full;
	let toggle = () => {
		screenfull.toggle(qr);
		full = !full;
		if (full) src = lg;
		else src = sm;
	};
</script>

<button class="ml-5 md:ml-20 mt-5 md:mt-10 hover:opacity-80" on:click={back}>
	<Icon icon="arrow-left" style="w-10" />
</button>

<div class="container mx-auto max-w-lg px-4 space-y-2 md:space-y-5">
	<div>
		<h1 class="text-secondary text-center text-xl">Please pay</h1>

		<div class="flex w-full">
			<div class="mx-auto">
				<a href="/{username}" class="text-black font-semibold hover:opacity-80 mx-auto">
					<div class="flex my-auto">
						<Avatar user={invoice.user} size={20} />
						<div class="my-auto text-lg">{username}</div>
					</div>
				</a>
			</div>
		</div>
	</div>

	{#if !user || user.username === username || showQr}
		<div class="mx-auto">
			<img {src} class:p-4={full} class="w-[300px] mx-auto" bind:this={qr} on:click={toggle} />
		</div>

		{#if address}
			<div class="text-secondary">{address}</div>
		{/if}

		<div class="flex gap-2 justify-center">
			<button
				class="flex rounded-full border py-2 px-5 font-bold hover:opacity-80"
				on:click={() => copy(text)}
				><Icon icon="copy" style="mr-1" />
				<div>Copy</div></button
			>
		</div>
	{/if}

	<div class="space-y-2 w-80 mx-auto">
		{#if invoice.tip}
			<div class="flex justify-between">
				{$t('invoice.invoice')}
				<span>
					{f(amountFiat, currency)}
					<span class="text-secondary">{`${sat(amount)}`}</span>
				</span>
			</div>

			<div class="flex justify-between">
				{$t('invoice.tip')}
				<span
					>{f(tipAmount, currency)}
					<span class="text-secondary">{`${sat(tip)}`}</span>
				</span>
			</div>
		{/if}

		{#if amount > 0}
			<div class="flex flex-wrap justify-between font-bold text-2xl !my-5">
				<span class="mr-1">{$t('invoice.total')}</span>
				<span
					>{f(amountFiat + parseFloat(tipAmount), currency)}
					<span class="text-secondary font-normal">{`${sat(tip + amount)}`}</span></span
				>
			</div>
		{/if}
	</div>

	{#if user && user.username !== username}
		<div class="mx-auto my-auto flex gap-2 justify-center">
			<a href={`/send/${invoice.uuid}`}>
				<button class="text-lg rounded-full border py-3 px-7 font-bold hover:opacity-80">
					Pay now
				</button>
			</a>
			<button
				class="text-lg rounded-full border py-3 px-7 font-bold hover:opacity-80"
				on:click={() => (showQr = !showQr)}
			>
				{showQr ? 'Hide' : 'Show'} QR
			</button>
		</div>
	{/if}
</div>

<style>
	.full {
		@apply p-8;
	}

	.full-shadow {
		box-shadow: inset 0 0 0 1000px rgba(0, 0, 0, 0.25);
	}
</style>